package daily;

public class TraditionalThreadCommunication {
	
	private void init(){
		final Business business=new Business();
		new Thread(new Runnable(){

			@Override
			public void run() {
				for(int i=0;i<50;i++){
					business.doSub();
				}
				
			}
			
		}).start();
		
		for(int i=0;i<50;i++){
			business.doMain();
		}
	}

	public static void main(String[] args) {
		TraditionalThreadCommunication ttc=new TraditionalThreadCommunication();
		ttc.init();
	}
	
	
	class Business{
		private boolean isSub=true;
		
		public synchronized void doSub(){
			while(!isSub){
				try {
					this.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			
			for(int i=0;i<10;i++){
				System.out.println(i+"    doSub--------");
			}
			isSub=false;
			this.notify();
		}
		
		public synchronized void doMain(){
			while(isSub){
				try {
					this.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			
			for(int i=0;i<50;i++){
				System.out.println(i+"    doMain--------");
			}
			isSub=true;
			this.notify();	
		}
	}

}
